package com.gaoxizhe.ccc.dao;

import com.gaoxizhe.ccc.model.login.User;
import com.gaoxizhe.ccc.model.login.VerificationCode;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Repository
public interface UserDao {
    /**
     * @param email
     * @return
     * @desc 查询改邮箱是否被注册
     */
    @Select("select * from user where email=#{email}")
    User isExistUser(String email);

    /**
     * 用户注册
     *
     * @param user
     */
        @Insert("insert into user(id,email,password,nickname) values (#{id},#{email},#{password},#{nickname})")
    @SelectKey(keyProperty = "id", resultType = String.class, before = true, statement = "select replace(uuid(), '-', '') as id from dual")
    void addUser(User user);

    /**
     * 用户登录
     *
     * @param email
     * @param password
     * @return
     */
    @Select("select * from user where email=#{email} and password=#{password}")
    User login(@Param("email") String email, @Param("password") String password);

    /**
     * 通过ID查询用户信息
     *
     * @param userId
     * @return
     */
    @Select("select * from user where id=#{userId}")
    User QueryInfoById(String userId);

    /**
     *
     *  @author: Mr.gao
     *  @Date: 2019/9/24 22:30
     *  @Description: 通过邮箱查找验证码
     */

    @Select("select * from login_code where email = #{email} ")
    VerificationCode checkCode(String email);

    /**
     *
     *  @author: Mr.gao
     *  @Date: 2019/9/24 22:33
     *  @Description: 通过邮箱更改验证码
     */
    @Update("update login_code set code = #{code} where email = #{email}")
    void changeCode(@Param("email") String email,@Param("code") String code);

    /**
     *
     *  @author: Mr.gao
     *  @Date: 2019/9/24 22:42
     *  @Description: 保存验证码
     */
    @Insert("insert into login_code (email, code) VALUES (#{email},#{code})")
    void saveCode(@Param("email") String email,@Param("code") String code);

    /**
     *
     *  @author: Mr.gao
     *  @Date: 2019/9/24 22:48
     *  @Description: 通过邮箱删除验证码
     */
    @Delete("delete from login_code where email = #{email}")
    void deleteCode(String email);

    /**
     *
     *  @author: Mr.gao
     *  @Date: 2019/9/24 22:53
     *  @Description: 修改密码
     */
    @Update("update user set password = #{password} where email = #{email}")
    void ChangePassword(@Param("email") String email,@Param("password") String password);
}